import java.util.ArrayList;

public class Test7 {
    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<User>();
        User u1= new User("001","zhangsan","123456");
        User u2= new User("002","lisi","12345678");
        User u3= new User("003","wangwu","12345");
        list.add(u1);
        list.add(u2);
        list.add(u3);
       int flag = getIndex(list,"001");
        System.out.println(flag);
    }
    //根据id查找用户
    public static int getIndex(ArrayList<User> list,String id){
        for (int i = 0; i < list.size(); i++) {
            User u = list.get(i);
            String uid = u.getId();
            if(uid.equals(id)){
                //如果找到了直接返回true
               return i;
            }
        }
        //当前所以元素比较完毕,没有一样的
       return -1;
    }

}
